package com.itheima.mapDemo1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapDemo1 {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();

        map.put("aaa1", "aaaa1");
        map.put("aaa2", "aaaa2");
        map.put("aaa3", "aaaa3");
        map.put("aaa4", "aaaa4");
        map.put("aaa5", "aaaa5");

//        System.out.println(map);

        System.out.println("遍历方式1：键找值");

        /*
        * 遍历1：键找值
        * */
        Set<String> keys = map.keySet();
        // 增强for
        for (String key : keys) {
            System.out.println(map.get(key));
        }
        System.out.println("---------------");
        // 迭代器
        Iterator<String> it = keys.iterator();
        while(it.hasNext()){
            System.out.println(map.get(it.next()));
        }
        System.out.println("---------------");
        // Lambda表达式
        keys.forEach(s -> System.out.println(map.get(s)));
    }
}
